package com.enation.app.shop.front.api.payrecord.service;

import com.enation.app.shop.front.api.payrecord.entity.PayRecord;
import com.enation.framework.database.IDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("payRecordService")
public class PayRecordManager implements IPayRecordManager {
    @Autowired
    private IDaoSupport daoSupport;
    @Override
    public int Create(PayRecord payRecord) {
        this.daoSupport.insert("rbt_payrecord",payRecord);
        return 1;
    }

    @Override
    public List<PayRecord> getByUserAndType(Integer userid,Integer year,Integer month) {
        String sql="";
        if (month==null){
            sql+="select * from rbt_payrecord where user_id=?  AND  year(time)='"+year+"' and type_id is not null order by time desc";
            return this.daoSupport.queryForList(sql,PayRecord.class,userid);
        }else {
            sql+="select * from rbt_payrecord where user_id=?  AND  year(time)='"+year+"' and  month(time)='"+month+"' and type_id is not null order by time desc";
            return this.daoSupport.queryForList(sql,PayRecord.class,userid);

        }
    }
    public List<PayRecord> getByUserAndTypeBill(Integer userid,Integer year,Integer month){
        String sql="";
        if (month==null){
            sql+="select * from rbt_payrecord where user_id=?  AND  year(time)='"+year+"'  order by time desc";
            return this.daoSupport.queryForList(sql,PayRecord.class,userid);
        }else {
            sql+="select * from rbt_payrecord where user_id=?  AND  year(time)='"+year+"' and  month(time)='"+month+"'  order by time desc";
            return this.daoSupport.queryForList(sql,PayRecord.class,userid);

        }
    }
}
